package waitnotify;

import java.util.Scanner;

public class WaitingThreadMain {
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("main 시작");
		
		WaitingThread a = new WaitingThread();
		WaitingThread b = new WaitingThread();
		WaitingThread c = new WaitingThread();
		
		a.start();
		b.start();
		c.start();
		
		String menu = "";
		Scanner sc = new Scanner(System.in);
		boolean mainStopped = false;
		while (!mainStopped) {
			menu = sc.nextLine();
			if (menu.equals("STOPA")) {
				a.stopThread();
			}
			else if (menu.equals("STOPB")) {
				b.stopThread();
			}
			else if (menu.equals("STOPC")) {
				c.stopThread();
			}
			else if (menu.equals("WAITA")) {
				a.suspend();
			}
			else if (menu.equals("WAITB")) {
				b.suspend();
			}
			else if (menu.equals("WAITC")) {
				c.suspend();
			}
			else if (menu.equals("NOTIA")) {
				a.resume();
			}
			else if (menu.equals("NOTIB")) {
				b.resume();
			}
			else if (menu.equals("NOTIC")) {
				c.resume();
			}
			else if (menu.equals("STOPM")) {
				a.stopThread();
				b.stopThread();
				c.stopThread();
				mainStopped = true;
			}
			else if (menu.equals("STATE")) {
				System.out.println("A: " + a.getState());
				System.out.println("B: " + b.getState());
				System.out.println("C: " + c.getState());
			}
		}
		
		System.out.println("main 종료");
		
	}
	
}
